﻿
function checkName(rename) {
	if (rename.length != 0) {
		document.getElementById("showNameError").innerHTML = "";
	}else {
		document.getElementById("showNameError").innerHTML = "<font color='red' size='2'>姓名欄不能為空的</font>";
	}
}
function checkPassword(repassword) {
	if (repassword.length>4 && repassword.length<12) {
		document.getElementById("showPasswordError").innerHTML = "";
	}else {
		document.getElementById("showPasswordError").innerHTML = "<font color='red' size='2'>密碼數小於5大於12,請重新輸入</font>";
	}
}
function checkEmail(remail) {
	if (remail.search(/^\w+[.a-zA-Z0-9_-]*@\w+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)!=-1) {
		document.getElementById("showEmailError").innerHTML = "";
	}else {
		document.getElementById("showEmailError").innerHTML = "<font color='red' size='2'>電子信箱格式不正確，請重新輸入</font>";
	}
}
function checkAddress(readdress) {
	if (readdress.length != 0) {
		document.getElementById("showAddressError").innerHTML = "";
	}else {
		document.getElementById("showAddressError").innerHTML = "<font color='red' size='2'>地址欄位不能為空的</font>";
	}
}
function checktel(rtel) {
	var re = /^\d+$/;
	if (re.test(rtel)) {
		document.getElementById("showPhoneError").innerHTML = "";
	}else {
		document.getElementById("showPhoneError").innerHTML = "<font color='red' size='2'>電話欄位不能為空的</font>";
	}
}
//function checkmobile( remobile ){
//	if ( remobile.match(/^09[0-9]{8}$/)) {
//		document.getElementById("showMobileError").innerHTML = "";
//	}else {
//		document.getElementById("showMobileError").innerHTML = "<font color='red' size='2'>手機不可空白!長度必須是10，不可以是文字，必定要09帶頭。</font>";
//	}
//}







var xhr = null;

function createXHR(){ //回傳一個非同步的請求物件	  
	 var xhr;
	 if (window.XMLHttpRequest)
	     xhr = new XMLHttpRequest();
	 else if ( window.ActiveXObject)
	     xhr = new ActiveXObject("Microsoft.XMLHttp");
     else 
	     xhr = null ;
	return xhr;	
}
//*************************checkId**********************************************
function stateChanged_1(){  
	if(xhr.readyState == 4) {
		if (xhr.status==200){
	   		document.getElementById("showAccountError").innerHTML = xhr.responseText;
		}
	}
}
function checkAccount(emp_account){  
	xhr =  createXHR();
	if (xhr ==null){
//		alert("Does not support");
		return;
	} 		
	xhr.onreadystatechange = stateChanged_1;	
	xhr.open("Get", "emp.do?action=checkEmployeeAccount&emp_account=" + emp_account, true);
	xhr.send(null);
}
//*************************checkMobile******************************************
function stateChanged_2(){  
	if(xhr.readyState == 4) {
		if (xhr.status==200){
	   		document.getElementById("showMobileError").innerHTML = xhr.responseText;
		}
	}
}
function checkMobile(emp_mobile){  
	xhr =  createXHR();
	if (xhr ==null){
//		alert("Does not support");
		return;
	} 		
	xhr.onreadystatechange = stateChanged_2;	
	xhr.open("Get", "emp.do?action=checkEmployeeMobile&emp_mobile=" + emp_mobile, true);
	xhr.send(null);
}



